<#include "/common/head.html"/> 
<table id="dg"></table>
<div id="tb" style="padding:2px 5px;">
		<input type="hidden" id="activityid" name="activityid" value="${activityid!''}"></input>
        <div style="text-align: left; margin:6px;">
            <a href="javascript:void(0)" class="easyui-linkbutton addBtn" iconCls="glyphicon-plus" plain="true" onclick="add()">新增</a>
            <a href="javascript:void(0)" class="easyui-linkbutton updateBtn" iconCls="glyphicon-pencil" plain="true" onclick="update()">编辑</a>
            <a href="javascript:void(0)" class="easyui-linkbutton addBtn" iconCls="glyphicon-remove" plain="true" onclick="delete1()">删除</a>
        </div>
    </div>
    	<div id="win" class="easyui-window" title="图片预览"
				style="width: 250px; height: 200px"
				data-options="iconCls:'icon-save',modal:true" closed="true">
				<img id="photo">
		</div>
<script type="text/javascript">
var aa = $("#activityid").val();
var datagrid = $("#dg");
var dgOptions = {
        rownumbers:true,
    	fit:true,
    	border:false,
    	striped:true,
        rownumbers:true,
    	url:'listDataInfo?activityid='+aa,
    	method:'post',
    	toolbar:'#tb',
    	pageSize: 20,
    	pagination:true,
    	multiSort:true,
    	singleSelect:true,
    	columns: [[
 				  {field:'id', title:'id', width:100}
 				 ,{field:'goodsname', title:'名称', width:100}
 	           	 ,{field:'imageurl', title: '图片', width:100,formatter:formatOprate}
 		         ,{field:'productid',title: '商品ID', width:80}
 	           	 ,{field:'mername', title: '供货商', width:80}
 	           	 ,{field:'goodsdesc', title: '广告说明', width:150}
 	           	 ,{field:'adstate', title: '状态', width:80,formatter:formatadstate} 
 	           	,{field:'sort', title: '排序', width:80}
 	           	,{field:'categoryname', title: '商品分类', width:113}
 	           	,{field:'real_amount_yuan', title: '商品价格', width:113}
 	           	,{field:'paytype', title: '支付方式', width:113,formatter:formatpaytype}
 	           	,{field:'state', title: '上下架状态', width:80,formatter:formatstate}
 	           ]]
 	};
$(function() {
	datagrid.datagrid(dgOptions);
});	

function add() {
	var activityid = $("#activityid").val();
	location.replace('addcurationPage?activityid='+activityid);
}

function update() {
	var rowsSel = datagrid.datagrid("getSelections");
	if(rowsSel.length != 1) {
		showWarnMsg("请选择一条数据！");
		return;
	}
	var id = rowsSel[0].id;
	location.replace('updatecurationPage?id='+id);
}

function delete1() {
	var rowsSel = datagrid.datagrid("getSelections");
	if(rowsSel.length != 1) {
		showWarnMsg("请选择一条数据！");
		return;
	}
	var id = rowsSel[0].id;
	confirmMsg("确认删除吗？", function() {
		$.post("deleteinfo", {id: id}, function(data) {
			var result = data.result;
			if(result=='success'){
				showMsg("删除成功！");
				datagrid.datagrid("reload");
			}else{
				showWarnMsg(result);
        		return;
			}
		});
	});
}

function getInitParam() {
	var param ={};
	$("#tb :input[name]").each(function(i, item) {
		if($(item).val()) {
			param["queryParams[" + $(item).attr("name") + "]"] = $(item).val().trim();	
		}
	});
	return param;
}


function formatstate(value,row,index){
	if(value == 0){
		return "下架";
	}else if(value == 1){
		return "上架";
	}
}

function formatadstate(value,row,index){
	if(value == 0){
		return "启用";
	}else if(value == 1){
		return "禁用";
	}
}

function formatpaytype(value,row,index){
	if (value == "comb") {
		return "固定积分+现金";
	}else if(value == "cust"){
		return "任意积分";
	}else if (value == "points") {
		return "全积分";
	}else if (value == "cash") {
		return "现金";
	}
	
}

function formatOprate(value,row,index){
	var adpicture = row.adpicture;
	var html = "<a style='color:blue' href='javascript:void(0);' onclick=\"tolook('" + adpicture + "')\"'>预览</a>";
	return html; 
}

function tolook(adpicture){
	$("#photo").attr('src',adpicture);
	$('#win').window('open'); // open a window 
}

</script>
<#include "/common/dialogWindow.html"/>
<#include "/common/foot.html"/>